package main

import "fmt"

/**
 * @author: guangcheng
 * @date:   2020/11/18 16:45
 * @version  V1.0
 * @description:
 *
 */
func main() {

	users := make(map[string]map[string]string)
	users["smith"] = make(map[string]string, 2)
	users["smith"]["pwd"] = "00000000"
	users["smith"]["nickname"] = "小花猫"

	fmt.Println(users)
	modifyUser(users, "smith")
	fmt.Println(users)

	modifyUser(users, "tom")
	fmt.Println(users)

	modifyUser(users, "cat")
	fmt.Println(users)
}

func modifyUser(users map[string]map[string]string, name string) {
	//判断users中是否有name
	//v, ok :=users[name]
	if users[name] != nil {
		//存在改用户
		users[name]["pwd"] = "12345678"
	} else {
		//不存在该用户
		users[name] = make(map[string]string, 2)
		users[name]["pwd"] = "12345678"
		users[name]["nickname"] = "昵称: " + name
	}
}
